import { createStore } from 'vuex'

export default createStore({
  state: {
    accessToken: null,
    userId: null,
    currentActive: "/dashboard",
    currentBreadcrumb: null,
    isCollapse: false
  },
  mutations: {
    setToken(state, token) {
      state.token = token
      localStorage.token = token
    },
    clearToken(state) {
      state.token = null
      localStorage.removeItem("token");
    },
    setCollapse(state, isCollapse) {
      state.isCollapse = isCollapse;
      sessionStorage.isCollapse = isCollapse;
    },
    setDefaultActive(state, active) {
      state.currentActive = active;
    },
    setBreadcrumb(state, matched) {
      state.currentBreadcrumb = matched;
    }
  },
  getters: {
    getToken(state) {
      if (!state.token) {
        state.token = localStorage.getItem('token')
      }
      return state.token
    },
    getDefaultActive(state) {
      return state.currentActive;
    },
    getCollapse(state) {
      let isCollapse = sessionStorage.getItem('isCollapse');
      if (isCollapse != null) {
        state.isCollapse = (isCollapse == 'true' ? true : false);
      }
      return state.isCollapse;
    },
    getBreadcrumb(state) {
      return state.currentBreadcrumb;
    }
  },
  actions: {
  },
  modules: {
  }
})